package hu.codeguide.xml;

import java.util.List;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

/**
 *
 * @author David Csejtei, CodeGuide Team, http://codeguide.hu
 */

public class RssParser {
    
    private static RssParser OB;
    private String url;
    
    private RssParser(final String url) {
        if(this.url == null) {
            this.url = url;
        }
    }

    public String getUrl() {
        return url;
    }
    
    public static RssParser getInstance(final String url) {
        if(OB == null) {
            OB = new RssParser(url);
        }
        return OB;
    }
    
    public List<RssItem> getItems() throws Exception {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        RssHandler handler = new RssHandler();
        saxParser.parse(url, handler);
        return handler.getRssItems();
    }
    
}
